package kassiopeia.agent.infrastructure;

import kassiopeia.plugin.Event;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;

@Component
@ManagedResource
public class EventRouterMBean {

    private static final Logger logger = Logger.getLogger(EventRouterMBean.class);

    @Autowired
    private EventRouter eventRouter;

    @ManagedOperation(
            description="Sends sample event using EventRouter")
    @ManagedOperationParameters({
        @ManagedOperationParameter(name="eventBody", description="Text which will be used as event body")
    })
    public void sendSampleEvent(String eventBody) {
        try {
            Event event = new Event(eventBody);
            eventRouter.routeEvent(event, "sampleInstanceId", "sampleOutputId");
        } catch(Exception exception) {
            logger.error(exception,exception);
        }
    }
}
